<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">甲方订单统计</ui:define>
    <ui:define name="content">
        <h:form>
            <p:defaultCommand target="search"/>
            <div class="topbar clearfix"
                 style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="left">
                        <p:commandButton value="批量模式"
                                         icon="fa fa-list-ul"
                                         actionListener="#{receiptOrderStatisticsBean.changeModeToBatch}"
                                         update="@form"
                                         process="@this"
                                         rendered="#{receiptOrderStatisticsBean.isNotBatch()}"/>
                        <p:commandButton value="常规模式" icon="fa fa-file"
                                         actionListener="#{receiptOrderStatisticsBean.changeModeToNormal}"
                                         process="@this"
                                         update="@form"
                                         rendered="#{receiptOrderStatisticsBean.isBatch()}"/>
                        <p:commandButton id="toggler" type="button" value="展示选择"
                                         style="width: auto;"
                                         icon="ui-icon-calculator"/>
                        <p:columnToggler datasource="orderStatisticsDataTable" trigger="toggler"/>
                    </f:facet>
                    <f:facet name="right">
                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                         update="@form"
                                         rendered="#{receiptOrderStatisticsBean.isNormal()}"/>
                        <p:commandButton value="重置" icon="fa fa-refresh"
                                         actionListener="#{receiptOrderStatisticsBean.onReset}"
                                         process="@this"
                                         update="@form"
                                         rendered="#{receiptOrderStatisticsBean.isNormal()}"/>
                        <p:commandButton value="导出" icon="fa fa-download"
                                         ajax="false">
                            <p:dataExporter type="xls" target="orderStatisticsDataTable" fileName="order-statistics"/>
                        </p:commandButton>

                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-fluid" style="padding-top: 30px;">
                <div class="ui-g">
                    <div class="ui-g-12">
                        <div class="card ui-g-12">
                            <div class="ui-g-12">
                                <h3><b>查询条件</b></h3>
                            </div>
                            <div class="ui-g-1">
                                <p:outputLabel value="日期"/>
                            </div>
                            <div class="ui-g-5">
                                <p:calendar value="#{receiptOrderStatisticsBean.$.startDate}"
                                            styleClass="autoWidthCalendar"
                                            locale="#{constants:get('LOCALE')}"
                                            timeZone="#{constants:get('TIME_ZONE')}"
                                            pattern="#{constants:get('DATE_FORMAT')}"
                                            readonlyInput="true"/>
                                <span>—</span>
                                <p:calendar value="#{receiptOrderStatisticsBean.$.endDate}"
                                            styleClass="autoWidthCalendar"
                                            locale="#{constants:get('LOCALE')}"
                                            timeZone="#{constants:get('TIME_ZONE')}"
                                            pattern="#{constants:get('DATE_FORMAT')}"
                                            readonlyInput="true"/>
                            </div>

                            <div class="ui-g-1">
                                <p:outputLabel value="产品名称"/>
                            </div>
                            <div class="ui-g-5">
                                <p:selectOneMenu filter="true"
                                                 filterMatchMode="contains"
                                                 value="#{receiptOrderStatisticsBean.$.receiptProductId}">
                                    <f:selectItem itemLabel="- 全部 -" itemValue="" noSelectionOption="true"/>
                                    <f:selectItems
                                            value="#{receiptOrderStatisticsBean.receiptProductInfos}"
                                            var="receiptProductInfo"
                                            itemLabel="#{receiptProductInfo.name}"
                                            itemValue="#{receiptProductInfo.id}"/>
                                </p:selectOneMenu>
                            </div>

                            <div class="ui-g-1">
                                <p:outputLabel value="订单来源"/>
                            </div>
                            <div class="ui-g-5">
                                <p:selectOneMenu filter="true"
                                                 filterMatchMode="contains"
                                                 value="#{receiptOrderStatisticsBean.$.sourceFrom}">
                                    <f:selectItem itemLabel="- 全部 -" itemValue="" noSelectionOption="true"/>
                                    <f:selectItems
                                            value="#{receiptOrderStatisticsBean.dictionaries[DictionaryCode.RECEIPT_ORDER_SOURCE_FROM]}"
                                            var="dic"
                                            itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                </p:selectOneMenu>
                            </div>

                            <div class="card ui-g-12">
                                <p:dataTable id="orderStatisticsDataTable"
                                             style="width: 100%"
                                             var="orderStatisticsRecord"
                                             value="#{receiptOrderStatisticsBean.lazyDataModel}"
                                             rows="#{constants:get('ROWS')}"
                                             lazy="true"
                                             paginator="true"
                                             paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                             rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                             emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                             scrollable="true"
                                             scrollWidth="97%"
                                             reflow="true"
                                             resizableColumns="true">

                                    <p:column headerText="日期">
                                        <h:outputText value="#{orderStatisticsRecord.date}">
                                            <f:convertDateTime pattern="#{constants:get('DATE_FORMAT')}"/>
                                        </h:outputText>
                                    </p:column>
                                    <p:column headerText="产品名称">
                                        <h:outputText value="#{orderStatisticsRecord.productName}"/>
                                    </p:column>
                                    <p:column headerText="订单来源">
                                        <h:outputText value="#{orderStatisticsRecord.sourceFromName}"/>
                                    </p:column>
                                    <p:column headerText="订单总数">
                                        <h:outputText value="#{orderStatisticsRecord.orderCount}"/>
                                    </p:column>
                                    <p:column headerText="结算金额">
                                        <h:outputText value="#{orderStatisticsRecord.settleAmount}"/>
                                    </p:column>
                                    <p:column headerText="等待审批">
                                        <h:outputText value="#{orderStatisticsRecord.waitingCount}"/>
                                    </p:column>
                                    <p:column headerText="审核中">
                                        <h:outputText value="#{orderStatisticsRecord.approvingCount}"/>
                                    </p:column>
                                    <p:column headerText="审核通过">
                                        <h:outputText value="#{orderStatisticsRecord.approvePassCount}"/>
                                    </p:column>
                                    <p:column headerText="拒绝">
                                        <h:outputText value="#{orderStatisticsRecord.rejectCount}"/>
                                    </p:column>
                                    <p:column headerText="已放款">
                                        <h:outputText value="#{orderStatisticsRecord.loanedCount}"/>
                                    </p:column>
                                    <p:column headerText="已取消">
                                        <h:outputText value="#{orderStatisticsRecord.cancelCount}"/>
                                    </p:column>
                                </p:dataTable>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </h:form>
    </ui:define>
</ui:composition>
